package com.ply.flashsalessystem.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ply.flashsalessystem.entity.pojo.ShopCar;
import com.ply.flashsalessystem.entity.vo.store.OrderForStoreVo;
import com.ply.flashsalessystem.entity.vo.user.ShopCarForGoodsVo;
import com.ply.flashsalessystem.entity.wrapper.ShopCarWrapper;
import com.ply.flashsalessystem.mapper.ShopCarMapper;
import com.ply.flashsalessystem.service.ShopCarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ply.flashsalessystem.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.ws.Action;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author XiaoPan
 * @since 2022-03-23
 */
@Service
public class ShopCarServiceImpl extends ServiceImpl<ShopCarMapper, ShopCar> implements ShopCarService {

    @Autowired
    ShopCarMapper shopCarMapper;

    @Override
    public boolean addShopCar(Integer goodsId, double goodsNums) {
        ShopCar shopCar = new ShopCar();
        shopCar.setGoodsId(goodsId);
        shopCar.setUserId(UserUtils.getUserId());
        shopCar.setGoodsNum(goodsNums);
        return shopCarMapper.insert(shopCar)!=0;
    }

    @Override
    public Page<ShopCarForGoodsVo> getGoodsOfShopCar(Integer current, Integer limit, ShopCarWrapper shopCarWrapper) {
        return shopCarMapper.getGoodsOfShopCar(new Page<>(current, limit), shopCarWrapper);
    }
}
